const http = require("http");
const fs = require("fs");
const path = require("path");

const server = http.createServer((req, res) => {
  fs.readFile(path.resolve(__dirname, "./a.png"), "binary", (error, result) => {
    // nodejs 错误处理优先
    if (error) {
      // 文件读取失败
    } else {
      res.writeHead(200, { "Content-Type": "image/png" });
      res.end(result, "binary");
    }
  });
});
server.listen(3000, () => {
  console.log("服务启动成功");
});

// http://localhost:3000

// http://localhost:3000/a.png => 图片
// http://localhost:3000/a.js => js
// http://localhost:3000/a.css => css

// express
